<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=0.4, maximum-scale=2.0, user-scalable=no">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>列表页</title>

    <!-- Bootstrap -->
    <link href="bootstrap/css/bootstrap.css" rel="stylesheet">
    <link href="./css/list.css" rel="stylesheet">
    <link href="./css/common.css" rel="stylesheet">
    <link href="//at.alicdn.com/t/font_902790_g8dm7878bt.css" rel="stylesheet">


</head>
<body>
<div class="page">
    <!--头部-->
    <div class="header-body">
        <div class="zs-header container">
            <div class="pull-left zs-header-logo">
                <a href="index.html" style="color: #009cd9;"><span>招商资源</span></a>
            </div>
            <div class="input-group search">
                <input id="search_info" type="text" class="form-control" placeholder="请输入关键字">
                <span class="input-group-btn">
                     <button id="search_btn" class="btn btn-default" type="button">搜索</button>
                </span>
            </div>
            <!-- /input-group -->
            <!--<div class="pull-right">-->
            <!--<ul class="zs-header-menu">-->
            <!--<li>首页</li>-->
            <!--<li>招商政策</li>-->
            <!--<li>产业信息</li>-->
            <!--<li>联系我们</li>-->
            <!--</ul>-->
            <!--</div>-->
        </div>
    </div>
    <!--头部-->

    <div class="content">
        <div class="container">
            <div class="content-title">
                <div id="list_title" class="list-title"></div>
            </div>
            <div class="content-list">
                <ul id="article_list" class="article-list">
                </ul>
                <nav aria-label="Page navigation" class="pull-right">
                    <ul class="pagination">
                    </ul>
                </nav>
            </div>
        </div>
    </div>

    <!-- 底部 -->
    <div class="placeholder"></div>
    <footer>
        <div class="container">
            <ul>
                <li>
                    <span>关注公众号</span>
                    <div class="qrcode">
                        <img id="qrcode" src="" alt="">
                    </div>
                </li>

                <li>
                    <span>联系方式</span>
                    <div class="contact">
                        <p id="phone" class="text-center"></p>
                        <p id="mail" class="text-center"></p>
                        <p id="address" class="text-center"></p>
                        <p id="fax" class="text-center"></p>
                        <p id="supportHotline" class="text-center"></p>
                    </div>
                </li>
                <li>
                    <span>其他</span>
                    <div class="other-service">
                        <div><a href="" class="other1"></a></div>
                        <div><a href="" class="other2"></a></div>
                        <div><a href="" class="other3"></a></div>
                    </div>
                </li>
                <li>
                    <span>单位概况</span>
                    <a href="" class="other4"></a>
                </li>
            </ul>
        </div>
        <div class="record">
            <div class="container">
                <div class="pull-left"><a href="http://www.gxbhipb.gov.cn/" class="footer-links" target="_blank">北海市投资促进局</a></div>
                <div class="pull-right">招商资源</div>
            </div>
        </div>
    </footer>
    <!-- 底部 -->
</div>

<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="js/jquery.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="js/jQuery-jcMarquee.js"></script>
<script src="js/init.js"></script>
<script>
    $(function () {
        if ($(window).width() <= 1170) {
            $("footer").find("li").css("padding", "0 38px");
        }
        var categoryId = getParameterByName("categoryId");
        var getPage = getParameterByName("page");
        var getPageSize = getParameterByName("pageSize");
        var search = getParameterByName("search");
        var nowPage = getPage ? getPage : 1;
        var pageSize = getPageSize ? getPageSize : 15;
        var postData = {};
        var postUrl = "/front/more";
        if (search) {
            postData = {
                title: search,
                page: nowPage,
                pageSize: pageSize
            };
            postUrl = "/front/search"
        } else {
            postData = {
                categoryId: categoryId,
                page: nowPage,
                pageSize: pageSize
            };
        }
        // 分类列表
        $.ajax({
            url: SERVICE_URL + postUrl,
            type: 'get',
            contentType: 'application/json',
            dataType: "json",
            data: postData,
            success: function (res) {
                if (res.code === 0) {
                    // 初始化赋值
                    var str = '';
                    var responseList = search ? res.data : res.data.page;
                    $(responseList.list).each(function (i, item) {
                        console.log(item);
                        var getDate = new Date(item.publishTime);
                        var publishTime = getDate.getFullYear() + '-' + (getDate.getMonth() + 1) + '-' + getDate.getDate();
                        categoryId = search ? item.categoryList[0].categoryId : categoryId;
                        str = str + '<li><a href="article.html?articleId=' + item.articleId + '&categoryId=' + categoryId + '">' + item.title + '<span style="float:right;margin-top:6px">' + publishTime + '</span></a></li>';
                    });
                    $("#article_list").html(str);
                    search ? $("#list_title").html(search+"-搜索结果") : $("#list_title").html(res.data.categoryName);


                    //分页
                    if (responseList.pages > 1) {
                        var pageList = '';
                        var nextPage = parseInt(nowPage) + 1;
                        var prePage = parseInt(nowPage) - 1;
                        pageList = '<li id="pre_page"><a href="list.html?categoryId=' + categoryId + '&page=' + prePage + '&pageSize=' + pageSize + '" aria-label="上一页"><span aria-hidden="true">&laquo;</span></a></li>';
                        for (var i = 1; i <= responseList.pages; i++) {
                            if (nowPage == i) {
                                if (search){
                                    pageList = pageList + '<li class="active"><a href="list.html?search=' + search + '&page=' + i + '&pageSize=' + pageSize + '">' + i + '</a></li>';
                                } else{
                                    pageList = pageList + '<li class="active"><a href="list.html?categoryId=' + categoryId + '&page=' + i + '&pageSize=' + pageSize + '">' + i + '</a></li>';
                                }
                            } else {
                                if (search){
                                    pageList = pageList + '<li><a href="list.html?search=' + search + '&page=' + i + '&pageSize=' + pageSize + '">' + i + '</a></li>';
                                } else{
                                    pageList = pageList + '<li><a href="list.html?categoryId=' + categoryId + '&page=' + i + '&pageSize=' + pageSize + '">' + i + '</a></li>';
                                }
                            }
                        }
                        if (search){
                            pageList = pageList + '<li id="next_page"><a href="list.html?search=' + search + '&page=' + nextPage + '&pageSize=' + pageSize + '" aria-label="下一页"><span aria-hidden="true">&raquo;</span></a></li>';
                        }else{
                            pageList = pageList + '<li id="next_page"><a href="list.html?categoryId=' + categoryId + '&page=' + nextPage + '&pageSize=' + pageSize + '" aria-label="下一页"><span aria-hidden="true">&raquo;</span></a></li>';
                        }

                        $(".pagination").html(pageList);
                        if (nowPage == 1) {
                            $("#pre_page").addClass("disabled");
                        }
                        if (nowPage == responseList.pages) {
                            $("#next_page").addClass("disabled");
                        }
                    }

                    //    菜单标注选中
                    if (categoryId == 21) {
                        $("#list2").addClass("zs-header-active");
                    } else if (categoryId == 31) {
                        $("#list3").addClass("zs-header-active");
                    } else {
                        $("#home_page").addClass("zs-header-active");
                    }

                } else {
                    alert("网络出错！");
                }
            },
            error: function () {
                alert("网络出错！");
            }
        });

        // 获取联系信息数据
        $.ajax({
            url: SERVICE_URL + '/front/contact',
            type: 'get',
            contentType: 'application/json',
            dataType: "json",
            success: function (res) {
                if (res.code === 0) {
                    $("#phone").text('联系电话：' + res.data.phone);
                    $("#mail").text('邮箱：' + res.data.mail);
                    $("#address").text('地址：' + res.data.address);
                    $("#qrcode").attr('src', res.data.qrcode);
                    $("#fax").text('传真：' + res.data.fax);
                    $("#supportHotline").text('咨询电话：' +  res.data.supportHotline);
                }
            },
            error: function () {

            }
        });

        // 单位概况
        $.ajax({
            url: SERVICE_URL + '/front/more',
            type: 'get',
            contentType: 'application/json',
            dataType: "json",
            data:{
                categoryId: 32,
            },
            success: function (res) {
                if (res.code === 0){
                    $(".other1").html(res.data.page.list[2].title);
                    $(".other1").attr('href',"article.html?categoryId=32&articleId="+res.data.page.list[2].articleId);
                    $(".other2").html(res.data.page.list[1].title);
                    $(".other2").attr('href',"article.html?categoryId=32&articleId="+res.data.page.list[1].articleId);
                    $(".other3").html(res.data.page.list[0].title);
                    $(".other3").attr('href',"article.html?categoryId=32&articleId="+res.data.page.list[0].articleId);
                    $(".other4").html(res.data.page.list[3].title);
                    $(".other4").attr('href',"article.html?categoryId=32&articleId="+res.data.page.list[3].articleId);
                }
            },
            error: function () {

            }
        });
        // 监听搜索
        $("#search_btn").click(function () {
            var searchInfo = $("#search_info").val();
            window.location.href = ('./list.html?search=' + searchInfo);
        });
    });
</script>
</body>
</html>